import json

# 读取jsonL列表和res文件，获得样本的统计数据
# 注意json文件读取的顺序和res保持一致
sampleNameList = []
successNameList = []
with open("/home/cyw/projects/malware_detected/saveData/test3/benign.jsonl","r") as file:
    for i in file.readlines():
        json_data =  json.loads(i)
        sampleNameList.append(json_data["sha256"])
with open("/home/cyw/projects/malware_detected/saveData/test3/malware.jsonl","r") as file:
    for i in file.readlines():
        json_data =  json.loads(i)
        sampleNameList.append(json_data["sha256"])

ind = 0
with open("/home/cyw/projects/malware_detected/saveData/test3/res.jsonl","r") as file:
    for i in file.readlines():
        json_data =  json.loads(i)
        json_data["sha256"]=sampleNameList[ind]
        if json_data["labelOrigin"] == json_data["labelPred"]:
            successNameList.append(sampleNameList[ind])
        ind+=1
        with open("/home/cyw/projects/malware_detected/saveData/test3/finalRes.jsonl","a+") as file1:
            res_data = json.dumps(json_data)
            file1.write(res_data+"\n"); 

with open("/home/cyw/projects/malware_detected/saveData/test3/nameRes.txt","a+") as file:
    file.write("检测样本的SHA256值，共计{}个：\n".format(len(sampleNameList)))
    file.write(str(sampleNameList)+"\n")
    file.write("样本识别成功的样本SHA256值，共计{}个\n".format(len(successNameList)))
    file.write(str(successNameList)+"\n")